package com.ruoyi.combat.service.apprisk.impl;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.combat.mapper.apprisk.CombatAppRiskMapper;
import com.ruoyi.combat.domain.apprisk.CombatAppRisk;
import com.ruoyi.combat.service.apprisk.ICombatAppRiskService;

/**
 * app风险Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-21
 */
@Service
public class CombatAppRiskServiceImpl implements ICombatAppRiskService 
{
    @Autowired
    private CombatAppRiskMapper combatAppRiskMapper;

    /**
     * 查询app风险
     * 
     * @param appRiskId app风险主键
     * @return app风险
     */
    @Override
    public CombatAppRisk selectCombatAppRiskByAppRiskId(Long appRiskId)
    {
        return combatAppRiskMapper.selectCombatAppRiskByAppRiskId(appRiskId);
    }

    /**
     * 查询app风险列表
     * 
     * @param combatAppRisk app风险
     * @return app风险
     */
    @Override
    public List<CombatAppRisk> selectCombatAppRiskList(CombatAppRisk combatAppRisk)
    {
        return combatAppRiskMapper.selectCombatAppRiskList(combatAppRisk);
    }

    @Override
    public List<Map<String, String>> userAppNum() {
        return combatAppRiskMapper.userAppNum();
    }

    /** 应用风险统计*/
    @Override
    public List<Map<String, String>> appRiskCount(){
        return combatAppRiskMapper.appRiskCount();
    }
    @Override
    public Long appCount(){
        return combatAppRiskMapper.appCount();
    }

    /**
     * 新增app风险
     * 
     * @param combatAppRisk app风险
     * @return 结果
     */
    @Override
    public int insertCombatAppRisk(CombatAppRisk combatAppRisk)
    {
        if(StringUtils.isNotEmpty(combatAppRisk.getRiskContent())) {
            CombatAppRisk combatAppRisk1 = new CombatAppRisk();
            combatAppRisk1.setAppId(combatAppRisk.getAppId());
            combatAppRisk1.setRiskContent(combatAppRisk.getRiskContent());
            List<CombatAppRisk> combatAppRisks = combatAppRiskMapper.selectCombatAppRiskList(combatAppRisk1);
            if (combatAppRisks.size() == 0) {
                return combatAppRiskMapper.insertCombatAppRisk(combatAppRisk);
            } else {
                return 1;
            }
        }
        return 0;
    }

    /**
     * 修改app风险
     * 
     * @param combatAppRisk app风险
     * @return 结果
     */
    @Override
    public int updateCombatAppRisk(CombatAppRisk combatAppRisk)
    {
        return combatAppRiskMapper.updateCombatAppRisk(combatAppRisk);
    }

    /**
     * 批量删除app风险
     * 
     * @param appRiskIds 需要删除的app风险主键
     * @return 结果
     */
    @Override
    public int deleteCombatAppRiskByAppRiskIds(Long[] appRiskIds)
    {
        return combatAppRiskMapper.deleteCombatAppRiskByAppRiskIds(appRiskIds);
    }

    /**
     * 删除app风险信息
     * 
     * @param appRiskId app风险主键
     * @return 结果
     */
    @Override
    public int deleteCombatAppRiskByAppRiskId(Long appRiskId)
    {
        return combatAppRiskMapper.deleteCombatAppRiskByAppRiskId(appRiskId);
    }
}
